<?php
include_once('bn_path.php');

 function jquery_submit_show($btnid,$func,$divid,$divshow='',$args=array())
{
    if($divshow=='')
    $divshow='#show';
    $bf='';
    if(!empty($args['befpost']))
    $bf=$args['befpost'];
    if(empty($args['adder']))
    $adder='window.location.href';
    else
    $adder='"'.$args['adder']."'";
    $cls='';
    if(!empty($args['cls']))
    $cls=$args['cls'];
    
    
    return      "\n$('$btnid').live('click',function(e){ 
                $bf
                $.post($adder,'cmd=$func&'+$('$divid :input').serialize(),function(data)
                {
                    if(data.length>0)
                    {
                        var containsHTML = new RegExp('.*\\<[^>]+>.*').test(data);
                        if(containsHTML)
                        $('$divshow').html(data);
                    else
                        alert(data);
                        $cls
                    }
                });
                });";  
}

 function jquery_submit_func($btnid,$func,$divid,$args=array())
{
    $bf=$args['befpost'];
    $adder='"'.$args['befpost']."'";
    if(empty($args['adder']))
    $adder='window.location.href';
    else
    $adder='"'.$args['adder']."'";
    $af=$args['afpost'];
    if($af!='')
      $af=",function(data){\n$af\n}";
      
      
    return    "\n$('$btnid').live('click',function(e){
              $bf
              $.post($adder,'cmd=$func&'+$('$divid :input').serialize()$af);
              });\n";  
}


function jquery_clear($btnid,$htmlid)
{
  return       "\n$('$btnid').live('click',function(e){ 
    
               var itm=$('$htmlid :input');
               itm.each(function(){
                
                     switch (this.tagName.toLowerCase()) 
                     {
                      case 'input':
                      switch (this.type) {
                      case 'radio':break;
                      case 'checkbox': this.checked = false; break;
                      case 'button':break;
                      case 'submit':break;
                      case 'image': break;
                      default: this.value = ''; break;
                     }break; 
                     case 'select': this.removeAttr('selected'); break;
                     case 'textarea': this.value = ''; break;
                     }
               });
                });";           
}

function jquery_select($selectid='',$args=array())
{
    if(empty($args['adder']))
    $adder='window.location.href';
    else
    $adder='"'.$args['adder']."'";
    $func=$args['afpost'];
    if($func!='')
      $func=",function(data){\n$func\n}";
    if($selectid=='')
     {
      $selectid='select';  
      $cmd='$(this).attr("id")'; 
     }     
     else
     $cmd="'$selectid'"; 
          
    return "   
           $('$selectid').live('change',function(){
           $.post($adder,{cmd:$cmd,value:$(this).val()}$func); 
           });";
}

function jquery_checkbox($selectid='',$args=array())
{
    if(empty($args['adder']))
    $adder='window.location.href';
    else
    $adder='"'.$args['adder']."'";
    $func=$args['afpost']; 
    if($func!='')
      $func=",function(data){\n$func\n}";
      
    if($selectid=='')
     {
        $selectid=':checkbox';
        $cmd='$(this).attr("id")'; 
     }     
     else
     $cmd="'$selectid'";     
    return "   
           $('$selectid').live('click',function(){
            var val='';
            if($(this).is(':checked')) 
            val='checked';
           $.post($adder,{cmd:$cmd,value:val}$func); 
           });";
}

function jquery_text($selectid='',$args=array())
{
    if(empty($args['adder']))
    $adder='window.location.href';
    else
    $adder='"'.$args['adder']."'";
    $func=$args['afpost'];
    if($func!='')
      $func=",function(data){\n$func\n}";
    if($selectid=='')
     {
      $selectid=':text';  
      $cmd='$(this).attr("id")'; 
     }     
     else
     $cmd="'$selectid'"; 
          
    return "   
           $('$selectid').live('change',function(){
           $.post($adder,{cmd:$cmd,value:$(this).val()}$func); 
           });";
}

function jquery_element($id,$event,$func)
{
    return "
    $('$id').live('$event',function(e){
    $func    
    });";
}
?>